#include "pdf.h"
#include "rtweekend.h"

double sphere_pdf::value(const vec3& direction) const
{
    return 1 / (4 * pi);
}

vec3 sphere_pdf::generate() const
{
    return random_unit_vector();
}

double cosine_pdf::value(const vec3& direction) const
{
    auto cosine_theta = dot(unit_vector(direction), uvw.w());
    return std::fmax(0, cosine_theta / pi);
}

vec3 cosine_pdf::generate() const
{
    return uvw.transform(random_cosine_direction());
}

double hittable_pdf::value(const vec3& direction) const
{
    return objects.pdf_value(origin, direction);
}

vec3 hittable_pdf::generate() const
{
    return objects.random(origin);
}
